package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"zeroOne/goods_srv/api/internal/svc"
	"zeroOne/goods_srv/api/internal/types"
	"zeroOne/goods_srv/rpc/goods"
)

type GoodsCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsCreateLogic {
	return &GoodsCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsCreateLogic) GoodsCreate(req *types.GoodsCreateRequest) (resp *types.ApiResponse, err error) {
	// todo: add your logic here and delete this line
	response, err := l.svcCtx.GoodsSrv.GoodsCreate(l.ctx, &goods.CreateGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsDesc:   req.GoodsDesc,
		GoodsPrice:  req.GoodsPrice,
		GoodsStock:  req.GoodsStock,
		GoodsStatus: int64(req.GoodsStatus),
		GoodsCover:  req.GoodsCover,
	})
	if err != nil {
		return &types.ApiResponse{
			Code:    -1,
			Message: "添加失败",
		}, nil
	} else {
		return &types.ApiResponse{
			Code:    200,
			Message: "添加成功",
			Data:    response.Id,
		}, nil
	}
}
